package model;

import java.util.concurrent.TimeUnit;

import mensch.Field;
import mensch.Game;

public class MenschBean {
	
	private Game game;
	
	public MenschBean() {
		game = new Game();
	}
	
	public int getNumberOfPlayers() {
		return game.getNumberOfPlayers();
	}
	
	public String getLeaderName() {
		return game.getLeaderName();
	}
	
	public int getCurrentRound() {
		return game.getCurrentRound();
	}
	
	public String getPlayerName(int playerID) {
		return game.getPlayers().get(playerID).getName();
	}
	
	public String getPlayerName() {
		return game.getActivePlayerName();
	}
	
	public int getCurrentDiceValue() {
		return game.getPlayerDiceValue();
	}
	
	public String getFieldTitle(int fieldIndex) {
		Field field = game.getTable().getFields().get(fieldIndex);
		String fieldTitle = field.getTitle();
		
		if (field.getPawnOnField() != null) {
			fieldTitle += ": " + field.getPawnOnField().getPlayer().getName();
		}
		
		return fieldTitle;
	}
	
	public String getFieldImageFilename(int fieldIndex) {
		Field field = game.getTable().getFields().get(fieldIndex);
		String fieldImageFilename = field.getImageFilename();
		
		if (field.getPawnOnField() != null) {
			fieldImageFilename += "_player" + (field.getPawnOnField().getPlayer().getPlayerID()+1);
		}
		
		return fieldImageFilename + ".png";
	}
	
	public String getRecentDiceValues() {
		return game.getOpponentDiceValues();
	}
	
	public boolean isInProgress() {
		return game.isInProgress();
	}
	
	public String getTime() {
		long time = game.getTime();
		return String.format("%d min, %d sec", TimeUnit.MILLISECONDS
				.toMinutes(time), TimeUnit.MILLISECONDS.toSeconds(time),
				TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
						.toMinutes(time)));
	}
	
	public void startTurn() {
		game.startTurn();
	}
}
